<?php
  include_once ("inc/startup.php");
  include ("inc/header.php");
  //CONTENT
  //Codierung: ANSI...
  //DATENÜBERGABE FORMULAR
  
  if (isset($_POST['count'])){
  
	$data = array();

	//Anzahl der angezeigten Plätze ermitteln
	$count = $_POST['count'];

	//gewählte Kategorie ermitteln
	if ($_POST['categories'] == "all"){
		$category = "*";
	}
	else{
		$category = $_POST['categories'];
	}

	//ermitteln, ob Spieler oder Spiele
	if ($_POST['mode'] == "games"){
		$mode = "games";
	}
	else{
		$mode = "users";
	}
	
	//gewählte Spieler ermitteln
	if ($_POST['player'] == "all"){
		$player = "*";
	}
	else{
		$player = $_POST['player'];
	}
	
	//gewählten Spielmodus ermitteln
	if ($_POST['gameMode'] == "*"){
		$gameMode = "*";
	}
	else{
		$gameMode = $_POST['gameMode'];
	}
	
	

	$data[0] = $count;
	$data[1] = $category;
	$data[2] = $mode;
	$data[3] = $player;
	$data[4] = $gameMode;
	
}
  //ENDE DATENÜBERGABE FORMULAR	


  if (isset($_SESSION['user'])){

	if (($_SESSION['user']->getRole()=='admin')){
		$statistic = new TStats('admin');
	}
	else{
		$statistic = new TStats('user');
	}
 }else{
	$statistic = new TStats('anonym'); 

  }
  

	$view = new TStatsView();
		
	if (isset($_POST['count'])){
		$view->getForm1WithData($data);
	}
	else{	
	$view->getForm1();
	}

	if (isset($_POST['categories'])){
	
		$view->fillCategoriesWithData($data,$statistic->getAllCategories());
	}
	else{	
		$view->fillCategories($statistic->getAllCategories());
	}

		
	if (isset($_POST['gameMode'])){
		$view->getForm2WithData($data);
	}
	else{	
		$view->getForm2();
	}
		if (isset($_POST['player'])){
			$view->getPlayersWithData($data[3],$statistic->fillPlayers());
		}else{
			$view->getPlayers($statistic->fillPlayers());
		}
	
	if (isset($_POST['mode'])){
		$view->getForm3WithData($data);
	}else{
		$view->getForm3();
	}


	//Tablle erstellen
	if (isset($_POST['count'])){
		

		$view->getTable($data, $statistic->getTableData($data));
	}
	
	$view->endContent();


//</div>	


include ("inc/footer.php"); ?>